<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Access {
	protected $CI;
	protected $user_model;
	
	function __construct() {
		$this->CI =& get_instance();
		$this->CI->load->model('user_model');
		$this->user_model =& $this->CI->user_model;
	}
	
	function login($usr,$pwd){
		$login_result = $this->user_model->check_login($usr,$pwd);
		if($login_result){
			$user_data = array(
				'id'=>$login_result['user_id'],
				'nama'=>$login_result['nama'],
				'level'=>$login_result['user_level'],
				'cabang'=>$login_result['kode_cabang'],
                                'kota'=>$login_result['nama_kota'],
				'loggedin'=>TRUE
			);
			$this->CI->session->set_userdata($user_data);
			return TRUE;
		}else{
			return FALSE;
		}
	}
	
	function is_login(){
		return ($this->CI->session->userdata('loggedin'));
	}
	
	function logout(){
		$this->CI->session->unset_userdata('id');
		$this->CI->session->unset_userdata('nama');
		$this->CI->session->unset_userdata('level');
		$this->CI->session->unset_userdata('cabang');
		$this->CI->session->unset_userdata('loggedin');
	}
}
/** End of file */